from django.db import models
from django.contrib.auth.models import User


# Create your models here.
class UserProfile(models.Model):
    User_Gender_TYPE = (
        ('male', "男"),
        ('female', "女")
    )
    owner = models.OneToOneField(User, on_delete=models.CASCADE, verbose_name='用户')
    nike_name = models.CharField(max_length=50, verbose_name='昵称', blank=True, default='')
    birthday = models.DateField(verbose_name='生日', blank=True, null=True)
    gender = models.CharField(max_length=10, verbose_name='性别', choices=User_Gender_TYPE, default='')
    image = models.ImageField(upload_to='images/%Y/%m', verbose_name='用户头像', default='images/default.png',
                              max_length=100)
    address = models.CharField(max_length=100, verbose_name='地址', blank=True, default='')

    class Meta:
        # 设置模型的单数显示名称
        verbose_name = '用户信息'
        # 设置模型的复数显示名称
        verbose_name_plural = verbose_name

    def __str__(self):
        # 返回对象的字符串表示，使用所有者的用户名
        return self.owner.username


class EmailVerifyRecord(models.Model):
    """邮箱验证码校验记录"""
    # objects = None
    SEND_TYPE_CHOICES = (
        ('register', '注册'),
        ('forget', '找回密码'),
    )
    code = models.CharField(max_length=20, verbose_name='验证码')
    email = models.EmailField(max_length=50, verbose_name='邮箱')
    send_type = models.CharField(max_length=10, choices=SEND_TYPE_CHOICES, default='register')

    class Meta:
        verbose_name = '邮箱验证码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.code
